/*
 * MapObject.cpp
 *
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses 
 */

#include "MapObject.h"
#include "ModelConstants.h"
#include "Events.h"

MapObject::MapObject(int x, int y) {
    init(x, y);
}

MapObject::MapObject(int id, int x, int y)
    : Identifiable(id) {
    init(x, y);
}

MapObject::MapObject(int x, int y, string typeXml) {
    init(x, y);
    this->typeXml = typeXml;
}

MapObject::MapObject(int id, int x, int y, string typeXml)
    : Identifiable(id) {
    init(x, y);
    this->typeXml = typeXml;
}

void MapObject::init(int x, int y) {
    this->x = x;
    this->y = y;
    resistance = -1;
    alignment = AL_NEUTRAL;
    points = 0;
    entered = false;
}

int MapObject::getResistance() {
    return resistance;
}

int MapObject::getAlignment() {
    return alignment;
}

int MapObject::getPoints() {
    return points;
}

bool MapObject::hasEnteredTheMap() {
    return entered;
}

void MapObject::setEnteredTheMap(bool entered_the_map) {
    entered = entered_the_map;
}

void MapObject::receiveDamage(int damage, MapObject* from) {
    resistance -= damage;
    if (isDestroyed()) {
        notify(OBJECT_DESTROYED, this, from);
    }
}

void MapObject::destroy() {
    receiveDamage(resistance);
}

bool MapObject::isDestroyed() {
    return resistance < 1;
}

bool MapObject::collideWith(MapObject* object) {
    return object->getCollidedBy(this);
}

bool MapObject::getCollidedBy(MapObject* object) {
    return false;
}

MapObject* MapObject::clone() {
    return new MapObject(*this);
}

ModelObject MapObject::getRepresentation() {
    return NO_REPRESENTATION;
}

MapObject::~MapObject() {

}

void MapObject::setTypeXml(string typeXml){
	this->typeXml = typeXml;
}

string MapObject::getTypeXml(){
	return this->typeXml;
}
